home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / f_brightcont.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  5.3 KB  |  192 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <windows.h>
  21. #include <commctrl.h>
  22.  
  23. #include "resource.h"
  24. #include "filter.h"
  25. #include "ScriptValue.h"
  26. #include "ScriptInterpreter.h"
  27. #include "ScriptError.h"
  28.  
  29. extern HINSTANCE g_hInst;
  30.  
  31. extern "C" void asm_brightcont1_run(
  32.         void *dst,
  33.         unsigned long width,
  34.         unsigned long height,
  35.         unsigned long stride,
  36.         unsigned long multiplier,
  37.         unsigned long adder1,
  38.         unsigned long adder2
  39.         );
  40.  
  41. extern "C" void asm_brightcont2_run(
  42.         void *dst,
  43.         unsigned long width,
  44.         unsigned long height,
  45.         unsigned long stride,
  46.         unsigned long multiplier,
  47.         unsigned long adder1,
  48.         unsigned long adder2
  49.         );
  50.  
  51. ///////////////////////////////////
  52.  
  53. struct MyFilterData {
  54.     LONG bright;
  55.     LONG cont;
  56. };
  57.  
  58. int brightcont_run(const FilterActivation *fa, const FilterFunctions *ff) {    
  59.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  60.  
  61.     if (mfd->bright>=0)
  62.         asm_brightcont2_run(
  63.                 fa->src.data,
  64.                 fa->src.w,
  65.                 fa->src.h,
  66.                 fa->src.pitch,
  67.                 mfd->cont,
  68.                 mfd->bright*0x00100010L,
  69.                 mfd->bright*0x00001000L
  70.                 );
  71.     else
  72.         asm_brightcont1_run(
  73.                 fa->src.data,
  74.                 fa->src.w,
  75.                 fa->src.h,
  76.                 fa->src.pitch,
  77.                 mfd->cont,
  78.                 (-mfd->bright)*0x00100010L,
  79.                 (-mfd->bright)*0x00001000L
  80.                 );
  81.  
  82.     return 0;
  83. }
  84.  
  85. long brightcont_param(FilterActivation *fa, const FilterFunctions *ff) {
  86.     fa->dst.offset    = fa->src.offset;
  87.     fa->dst.modulo    = fa->src.modulo;
  88.     fa->dst.pitch    = fa->src.pitch;
  89.     return 0;
  90. }
  91.  
  92. //////////////////
  93.  
  94. static int brightcont_init(FilterActivation *fa, const FilterFunctions *ff) {
  95.     ((MyFilterData *)fa->filter_data)->bright = 0;
  96.     ((MyFilterData *)fa->filter_data)->cont = 16;
  97.  
  98.     return 0;
  99. }
  100.  
  101. static BOOL APIENTRY brightcontDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  102.     switch (message)
  103.     {
  104.         case WM_INITDIALOG:
  105.             {
  106.                 MyFilterData *mfd = (MyFilterData *)lParam;
  107.                 HWND hWnd;
  108.  
  109.                 hWnd = GetDlgItem(hDlg, IDC_BRIGHTNESS);
  110.                 SendMessage(hWnd, TBM_SETTICFREQ, 16, 0);
  111.                 SendMessage(hWnd, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG(0, 512));
  112.                 SendMessage(hWnd, TBM_SETPOS, (WPARAM)TRUE, mfd->bright+256);
  113.  
  114.                 hWnd = GetDlgItem(hDlg, IDC_CONTRAST);
  115.                 SendMessage(hWnd, TBM_SETTICFREQ, 4, 0);
  116.                 SendMessage(hWnd, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG(0, 32));
  117.                 SendMessage(hWnd, TBM_SETPOS, (WPARAM)TRUE, mfd->cont);
  118.  
  119.                 SetWindowLong(hDlg, DWL_USER, (LONG)mfd);
  120.             }
  121.             return (TRUE);
  122.  
  123.         case WM_COMMAND:                      
  124.             if (LOWORD(wParam) == IDOK) {
  125.                 MyFilterData *mfd = (struct MyFilterData *)GetWindowLong(hDlg, DWL_USER);
  126.  
  127.                 mfd->bright = SendMessage(GetDlgItem(hDlg, IDC_BRIGHTNESS), TBM_GETPOS, 0, 0)-256;
  128.                 mfd->cont = SendMessage(GetDlgItem(hDlg, IDC_CONTRAST), TBM_GETPOS, 0, 0);
  129.  
  130.                 EndDialog(hDlg, 0);
  131.                 return TRUE;
  132.             } else if (LOWORD(wParam) == IDCANCEL) {
  133.                 EndDialog(hDlg, 1);
  134.                 return TRUE;
  135.             }
  136.             break;
  137.     }
  138.     return FALSE;
  139. }
  140.  
  141. static int brightcont_config(FilterActivation *fa, const FilterFunctions *ff, HWND hWnd) {
  142.     return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_FILTER_BRIGHTCONT), hWnd, brightcontDlgProc, (LONG)fa->filter_data);
  143. }
  144.  
  145. static void brightcont_string(const FilterActivation *fa, const FilterFunctions *ff, char *buf) {
  146.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  147.  
  148.     sprintf(buf," (bright %+d%%, cont %d%%)", (mfd->bright*25)/64, (mfd->cont*25)/4);
  149. }
  150.  
  151. static void brightcont_script_config(IScriptInterpreter *isi, void *lpVoid, CScriptValue *argv, int argc) {
  152.     FilterActivation *fa = (FilterActivation *)lpVoid;
  153.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  154.  
  155.     mfd->bright    = argv[0].asInt();
  156.     mfd->cont    = argv[1].asInt();
  157. }
  158.  
  159. static ScriptFunctionDef brightcont_func_defs[]={
  160.     { (ScriptFunctionPtr)brightcont_script_config, "Config", "0ii" },
  161.     { NULL },
  162. };
  163.  
  164. static CScriptObject brightcont_obj={
  165.     NULL, brightcont_func_defs
  166. };
  167.  
  168. static bool brightcont_script_line(FilterActivation *fa, const FilterFunctions *ff, char *buf, int buflen) {
  169.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  170.  
  171.     _snprintf(buf, buflen, "Config(%d,%d)", mfd->bright, mfd->cont);
  172.  
  173.     return true;
  174. }
  175.  
  176. FilterDefinition filterDef_brightcont={
  177.     0,0,NULL,
  178.     "brightness/contrast",
  179.     "Adjusts brightness and contrast of an image linearly.\n\n[Assembly optimized] [MMX optimized]",
  180.     NULL,NULL,
  181.     sizeof(MyFilterData),
  182.     brightcont_init,
  183.     NULL,
  184.     brightcont_run,
  185.     brightcont_param,
  186.     brightcont_config,
  187.     brightcont_string,
  188.     NULL,
  189.     NULL,
  190.     &brightcont_obj,
  191.     brightcont_script_line,
  192. };